<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/api.js"></script>
<script type="text/javascript" src="../../js/axios.js"></script>
<script type="text/javascript" src="../../js/jquery.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品类型管理</li>
    <li>添加</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>商品类型信息</span></div>
  <form id="form">
  <ul class="forminfo">
    <li>
      <label>品牌名称</label>
      <select class="dfselect" id="brand" name="brandName">
      	  <option>请选择</option>
          <option>联想</option>
          <option>海尔</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>商品类型名称</label>
      <input name="typeName" type="text" class="dfinput" id="typeName"/>
      <i class="typetip">必填，不能超过50个字符</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect" name="typeStatus">
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
      <input name="createId" type="hidden" id="createId" value="101"/>
      <input name="createName" id="createName" type="text" value="马云" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label> <!--value="2017-11-18 15:36:10" readonly="readonly"-->
      <input name="createTime" id="createTime" class="roinput" readonly="readonly"/>
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="" type="submit" class="btn" value="确定"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='productTypeList.html'"/>
    </li>
  </ul>
  </form>
</div>
<script type="text/javascript">
  $(function () {
    //获取当前时间
    let s = new Date().toLocaleString();
    s = s.replaceAll("/","-")
    $('#createTime').val(s);

    //获取user
    $('#createId').val(localStorage.getItem('uId'));
    $('#createName').val(localStorage.getItem('username'));

    //获取品牌信息
    brandname();

    $('#typeName').blur(check);

      $('#form').submit(function () {
        let type=$('#form').serializeArray();
        if (check()){
          axiosJson(
                  'get',//提交方法
                  '/purchase/addType',//提交地址
                  type,
                  null
          ).then((res) => {
            location.href="productTypeList.html";
          })
        }
        return false;
      })



  })

  function check() {
    let typeName=$('#typeName').val();
    if (typeName==null||typeName==''){
      $('.typetip').html("商品类型名称不能为空").css("color","red");
      return false;
    }else {
      $('.typetip').html("");
    }
    return true;
  }

  //品牌信息
  function brandname() {

    axiosJson(
            'get',//提交方法
            '/purchase/brandName',//提交地址
            null,
            null
    ).then((res) => {
      let audit = res.data.resultData
      let str=''
      for (let i=0;i<audit.length;i++){
        str+='<option>'+audit[i]+'</option>'
      }
      $('#brand').html(str)
    })
  }

</script>
</body>
</html>
